package com.ybl.wallet.controller;

import com.ybl.wallet.entity.Transactions;
import com.ybl.wallet.service.WalletService;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/wallet")
public class WalletController {
    private WalletService walletService;

    /**
     * 查询用户钱包余额
     * @param userId 用户id
     * @return 余额
     */
    @GetMapping("/balance")
    public double getBalance(@RequestParam("userId") Long userId) {
        return walletService.getBalance(userId);
    }

    /**
     * 用户消费
     * @param userId 用户id
     * @param amount 消费金额
     * @return 是否消费成功
     */
    @PostMapping("/consume")
    public boolean consume(@RequestParam("userId") Long userId, @RequestParam("amount") double amount) {
        return walletService.consume(userId, amount);
    }

    /**
     * 用户退款
     * @param userId 用户id
     * @param amount 退款金额
     * @return 是否退款成功
     */
    @PostMapping("/refund")
    public boolean refund(@RequestParam("userId") Long userId, @RequestParam("amount") double amount) {
        // 用户退款
        boolean success = walletService.refund(userId, amount);
        return success;
    }
}
